extends Object


class_name BehaviorHelper


static func is_layer(hit_layer_mask: int, e: CharacterEvent) -> bool:
    var body: Node2D = e.meta.body
    var body_rid: RID = e.meta.body_rid
    var layer: int = -1
    if body is Area2D:
        layer = body.collision_layer
    elif body is TileMap:
        layer = NodeHelper.get_tilemap_collision_layer(body, body_rid)
    elif body is TileMapLayer:
        layer = NodeHelper.get_tilemaplayer_collision_layer(body, body_rid)
    return (layer & hit_layer_mask) != 0


static func display_float_text(node: Node2D, text: String, color: Color) -> void:
    var label: Label = Label.new()
    label.text = text
    label.z_index = 1
    label.label_settings = LabelSettings.new()
    label.label_settings.font_color = color
    label.label_settings.font_size = 50
    label.label_settings.outline_color = "#272727"
    label.label_settings.outline_size = 16
    label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
    node.call_deferred("add_child", label)

    await label.resized
    var half_size: Vector2 = Vector2(label.size / 2)
    label.global_position = node.global_position - half_size
    label.pivot_offset = half_size

    var tween: Tween = node.get_tree().create_tween()
    tween.set_parallel(true)
    tween.tween_property(label, "position:y", label.position.y - 30, 0.25).set_ease(Tween.EASE_OUT)
    tween.tween_property(label, "position:y", label.position.y, 0.15).set_ease(Tween.EASE_IN).set_delay(0.25)
    tween.tween_property(label, "scale", Vector2.ZERO, 0.2).set_ease(Tween.EASE_IN).set_delay(0.15)
    await tween.finished
    label.queue_free()
